import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { ContentTagMapping } from './content-tag-mapping.entity';

@Entity('tags')
export class Tag {
  @ApiProperty({
    format: 'uuid',
    description: '标签的唯一标识',
  })
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty({
    maxLength: 64,
    description: '标签名称，最大长度64个字符',
  })
  @Column({ name: 'name', length: 64, unique: true })
  name: string;

  @OneToMany(() => ContentTagMapping, (mapping) => mapping.tag, {
    cascade: true,
    createForeignKeyConstraints: false,
  })
  contentMappings: ContentTagMapping[];
}
